#include "IDManager.h"

IDManager::IDManager()
: m_nStartID( 0 )
, m_nCurrentID( 0 )
, m_nEndID( 0 )
{

}

IDManager::~IDManager()
{

}

bool IDManager::Init( int nStartID/* = 0*/, int nEndID/* = -1*/ )
{
	if( nEndID != -1 && nStartID > nEndID )
		return false;

	m_nStartID = nStartID;
	m_nEndID = nEndID;
	m_nCurrentID = m_nStartID;

	return true;
}

int IDManager::GetID( )
{
	if( !m_aNoUseID.empty() )
	{
		int nID = m_aNoUseID.front();
		m_aNoUseID.pop_front();

		return nID;
	}

	if( m_nEndID != -1 && m_nCurrentID > m_nEndID )
		return -1;

	return m_nCurrentID++;
}

void IDManager::SetNoUseID( int nID )
{
	m_aNoUseID.push_back( nID );
}
